//
//  NSCoderClass.m
//  NSCoderDemo
//
//  Created by ellenpage on 12-11-28.
//  Copyright (c) 2012年 ellenpage. All rights reserved.
//
////传值传path+

#import "Constant.h"
#import "NSCoderClass.h"
#import "NSCoderObject.h"

@interface NSCoderClass ()

@end

@implementation NSCoderClass


+ (void)writeData:(NSString *)filePath dict:(NSMutableDictionary *)dict archiveName:(NSString *)nameStr
{
    
    NSMutableData   *data     = [NSMutableData data];
    NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
    
    NSCoderObject *testObject = [[NSCoderObject alloc] init];
    testObject.mydict = dict;
    
    [archiver encodeObject:testObject forKey:nameStr];
    [archiver finishEncoding];
    
    [data writeToFile:filePath atomically:YES];
}

+ (NSMutableDictionary *)readData:(NSString *)filePath dict:(NSMutableDictionary *)dict archiveName:(NSString *)nameStr
{
    
    NSData *data = [NSData dataWithContentsOfFile:filePath];
    if ([data length] > 0)
    {
        NSKeyedUnarchiver *unArchive = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
        
        NSCoderObject *object1 = [unArchive decodeObjectForKey:nameStr];
        
        [unArchive finishDecoding];
        return object1.mydict;
    }
    else
    {
        return nil;
    }
}


@end
